package com.jblapp.icu.http;

import java.util.List;

import org.apache.http.NameValuePair;
import org.json.JSONObject;

import android.content.Context;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

public class Register extends AbstractHttpRequest implements Runnable{

	private final static String TAG = "Register";
	private final static String URL = "http://icu.joblean.com.cn/user.php?action=reg";
	private List<NameValuePair> params = null;
	private String status=null;
	private Message msg=null;
	private Handler msgHandler=null;
	public Register(Handler msgHandler, List<NameValuePair> params ) {
		this.msgHandler=msgHandler;
		this.params = params;
	}

	@Override
	public Object parse(String jsonMsg) throws Exception {
		Log.e(TAG, jsonMsg);
		JSONObject json = new JSONObject(jsonMsg);
		int status = json.getInt("status");
		Log.e(TAG, "Register:" + status);
		return String.valueOf(status);
	}

	public String regStatus() throws Exception {
		// params.add(new BasicNameValuePair("flag", "1"));
		// params.add(new BasicNameValuePair("mobilephone", "+8618977914048"));
		// params.add(new BasicNameValuePair("password",
		// "14e1b600b1fd579f47433b88e8d85291"));
		// params.add(new BasicNameValuePair("current_longitude", "39915000"));
		// params.add(new BasicNameValuePair("current_latitude", "116404000"));
		// params.add(new BasicNameValuePair("reg_location", "+86"));
		String status = null;
		status = this.httpPostMethod(URL, params).toString();
		Log.e(TAG, "Status" + status);
		return status;
	}

	@Override
	public void run() {
		msg=new Message();
		try {
			status=regStatus();
			Log.e(TAG, status);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(status!=null){
			msg.what = Integer.parseInt(status);
			msgHandler.sendMessage(msg);
		}
	}
}
